package com.example.springblog.mapper;

import com.example.springblog.model.BlogInfo;
import com.example.springblog.model.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BlogMapper {
    // 根据 id 查询用户信息
//    @Select("select id, user_name, password, github_url, delete_flag, create_time, update_time " +
//            " from user_info where id = #{blogId}")
//    UserInfo selectUserIdById(int blogId);

    // 获取所有未被删除的博客列表
    @Select("select id, title, content, user_id, delete_flag, create_time, update_time from blog_info where delete_flag = 0 " +
            "order by create_time desc")
    List<BlogInfo> selectAllBlog();

    // 根据博客 id 查询博客信息
    @Select("select id, title, content, user_id, delete_flag, create_time, update_time  from blog_info where id = #{blogId}")
    BlogInfo selectById(int blogId);

    // 插入新的博客数据
    @Insert("insert into blog_info (title, content, user_id) values (#{title}, #{content}, #{userId})")
    int insertBlog(BlogInfo blogInfo);

    // 根据博客 id 修改博客
    int updateBlog(BlogInfo blogInfo);

}
